package org.zachary.prosocialbehaviorservice.infrastructure.repository;

import org.springframework.stereotype.Repository;
import org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity.ActivityItem;
import org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity.UserActivityParticipation;
import org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity_user.UserActivity;
import org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity_user.UserJoinActivityDTO;
import org.zachary.prosocialbehaviorservice.domain.repository.UserActivityParticipationRepository;

import java.util.List;
import java.util.Optional;

@Repository
public class JpaUserActivityRepository implements UserActivityParticipationRepository {
    private final SpringDataUserActivityRepository jpaRepo;

    public JpaUserActivityRepository(SpringDataUserActivityRepository jpaRepo) {
        this.jpaRepo = jpaRepo;
    }

    @Override
    public void joinActivity(UserActivity command) {
        jpaRepo.save(command);
    }

    @Override
    public void exitActivity(Integer userId, Integer itemId) {
        jpaRepo.deleteByUserIdAndActivityId(userId,itemId);
    }

    @Override
    public List<UserActivity> userAllActivities(Integer userId) {
        return jpaRepo.findByUserId(userId);
    }

    @Override
    public void finished(Integer userId, Integer itemId) {
        jpaRepo.finished(userId,itemId);
    }

    @Override
    public UserActivity findByUserItemId(Integer userId, Integer itemId) {
        return jpaRepo.findByUserIdAndItemId(userId,itemId);
    }
    @Override
    public List<UserJoinActivityDTO> findUserJoinActivities(Integer userId){
        return jpaRepo.findUserJoinedActivities(userId);
    }

}
